<template>
    <div>
        <button @click="handleClick" v-if="left">返回</button>
        Navbar---{{ computedTitle }}
        <button>前进</button>
    </div>
</template>

<script>
import { computed, getCurrentInstance } from 'vue';

export default {
    props: {
        title: String,
        left: Boolean
    },

    setup({ title }, { emit }) {//第一个参数props用来接收父传子的属性，这里title是解构写法；这里的emit是第二个形参解构出来的
        const _this = getCurrentInstance()
        console.log("$parent", _this.parent);
        console.log("$root", _this.root);

        const computedTitle = computed(() => title + "-666")

        const handleClick = () => {

            emit("leftEvent", "这是传给父组件的内容")
        }

        return {
            computedTitle,
            handleClick
        }
    },
}
</script>